<?php if (!defined('THINK_PATH')) exit(); /*a:1:{s:27:"themes/admin/user-list.html";i:1568365182;}*/ ?>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" href="/themes/admin/assets/css/layui.css">
  </head>
  <style>
    /*分页样式*/
    .pagination{text-align:center;margin-top:20px;margin-bottom: 20px;}
    .pagination li{margin:0px 10px; border:1px solid #e6e6e6;padding: 6px 12px;display: inline-block;}
    .pagination li:hover{background:#e6e6e6 }
    .pagination .active{background-color: #dd1a20;color: #fff;}
    .pagination .disabled{color:#aaa;}
  </style>
  <body>
    <table class="layui-table">
      <colgroup>
        <col width="150">
        <col width="200">
        <col>
      </colgroup>
      <thead>
        <tr>
          <th>头像</th>
          <th>用户名</th>
          <th>角色</th>
          <th>Email</th>
          <th>创建时间</th>
          <th>管理</th>
        </tr> 
      </thead>
      <tbody>
        <?php if(is_array($userList) || $userList instanceof \think\Collection || $userList instanceof \think\Paginator): $i = 0; $__LIST__ = $userList;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?>
        <tr>
          <td><img style="width:50px;height:50px" src="<?php echo $vo['avatar']; ?>" /></td>
          <td><?php echo $vo['username']; ?></td>
          <td><?php echo $vo['title']; ?></td>
          <td><?php echo $vo['email']; ?></td>
          <td><?php echo date("Y-m-d",$vo['create_time']); ?></td>
          <td>
            <div class="layui-btn-group">
              <button  onclick="roleUser(<?php echo $vo['uid']; ?>)" class="layui-btn layui-btn-primary layui-btn-sm">
                <i class="layui-icon">&#xe642;</i>
              </button>
              <button onclick="delectUser(<?php echo $vo['uid']; ?>)" class="layui-btn layui-btn-primary layui-btn-sm">
                <i class="layui-icon">&#xe640;</i>
              </button>
            </div>
          </td>
        </tr>      
        <?php endforeach; endif; else: echo "" ;endif; ?>
      </tbody>
    </table>
    <form id="roleForm" class="layui-form" action="" style="display: none;">
      <div class="layui-form-item">
        <div class="layui-input-block">
          <?php if(is_array($authGroup) || $authGroup instanceof \think\Collection || $authGroup instanceof \think\Paginator): $i = 0; $__LIST__ = $authGroup;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$v): $mod = ($i % 2 );++$i;?>
          <input type="radio" name="role" value="<?php echo $v['id']; ?>" title="<?php echo $v['title']; ?>">
          <?php endforeach; endif; else: echo "" ;endif; ?>
        </div></div><div class="layui-form-item">
      <div class="layui-input-block">
        <button class="layui-btn" lay-submit lay-filter="saveRole" onclick="saveRole(<?php echo $vo['uid']; ?>,<?php echo $v['id']; ?>)">保存</button>
        <button class="layui-btn layui-btn-primary">取消</button>
      </div>
      </div>
    </form>
    <?php echo $userList->render(); ?>
    <script src="/themes/admin/assets/layui.js"></script>
    <script src="/themes/admin/assets/jquery-3.2.1.min.js"></script>
    <script>
      layui.use('layer');
      layui.use('form');
      //删除用户
      function delectUser(userId){
        layer.msg('确定删除？', {
          time: 0 //不自动关闭
          ,btn: ['删除', '取消']
          ,yes: function(index){
            $.ajax({
              type:"post",
              data:"userId="+userId,
              url:"/admin/user/delete",
              success:function(e){
                if(e.code == 1){
                  location.href = "/admin/user/userList";
                  layer.msg(e.msg,{icon:1});
                }else{
                  layer.msg(e.msg);
                }
              }
            });
            layer.close(index);
          }
        });
      }

      //修改用户角色弹窗
      function roleUser(uid){
        layer.open({
          type: 1,
          title:"修改用户角色",
          skin: 'layui-layer-lan',
          closeBtn: 0,
          anim: 2,
          shadeClose: true,
          content: $("#roleForm")
        });
        //监听提交
        var form = layui.form;
        form.on('submit(saveRole)', function(data){
          var groupId = data.field.role;
          $.ajax({
            type:"post",
            data:{
              uid:uid,
              groupId:groupId
            },
            url:"/admin/user/updateRole",
            success:function(e){
              if(e.code == 1){
                location.href = "/admin/user/userList";
              }
              layer.msg(e.msg);
            }
          });
          return false;
        });
      }
    </script>
  </body>
</html>
